package com.ruoyi.project.business.timeperiod.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.model.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.business.timeperiod.entity.TimePeriod;
import com.ruoyi.project.business.timeperiod.request.AddTimePeriodRequest;
import com.ruoyi.project.business.timeperiod.request.ListTimePeriodRequest;
import com.ruoyi.project.business.timeperiod.response.TimePeriodResponse;
import com.ruoyi.project.business.timeperiod.service.ITimePeriodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工作站Controller
 * 
 * @author ${author}
 * @date 2024-04-01
 */
@RestController
@RequestMapping("/business/timeperiod")
public class TimePeriodController extends BaseController {
    @Autowired
    private ITimePeriodService timePeriodService;

    /**
     * 查询工作站列表
     */
    @PreAuthorize("@ss.hasPermi('business:timeperiod:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListTimePeriodRequest request) {
        startPage();
        Long tenantId = getTenantId();
        List<TimePeriodResponse> list = timePeriodService.selectTimePeriodList(request, tenantId);
        return getDataTable(list);
    }

    /**
     * 导出工作站列表
     */
    @PreAuthorize("@ss.hasPermi('business:timeperiod:export')")
    @Log(title = "工作站", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListTimePeriodRequest request) {
        Long tenantId = getTenantId();
        List<TimePeriodResponse> list = timePeriodService.selectTimePeriodList(request, tenantId);
        ExcelUtil<TimePeriodResponse> util = new ExcelUtil<>(TimePeriodResponse.class);
        return util.exportExcel(list, "timeperiod");
    }

    /**
     * 获取工作站详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:timeperiod:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(timePeriodService.selectTimePeriodById(id));
    }

    /**
     * 新增工作站
     */
    @PreAuthorize("@ss.hasPermi('business:timeperiod:add')")
    @Log(title = "工作站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddTimePeriodRequest request) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(timePeriodService.insertTimePeriod(request, operatorId, tenantId));
    }

    /**
     * 修改工作站
     */
    @PreAuthorize("@ss.hasPermi('business:timeperiod:edit')")
    @Log(title = "工作站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TimePeriod timePeriod) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(timePeriodService.updateTimePeriod(timePeriod, operatorId, tenantId));
    }

    /**
     * 删除工作站
     */
    @PreAuthorize("@ss.hasPermi('business:timeperiod:remove')")
    @Log(title = "工作站", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        Long tenantId = getTenantId();
        Long operatorId = getUserId();
        return toAjax(timePeriodService.deleteTimePeriodByIds(ids, operatorId, tenantId));
    }
}
